package main

import (
	"fmt"
	"net/http"
	"strings"

	"github.com/PuerkitoBio/goquery"
)

type Koolearn struct{}

func (k Koolearn) spider(url string) {
	res, err := http.Get(url)
	if err != nil {
		fmt.Println(err)
	}
	defer res.Body.Close()

	if res.StatusCode != 200 {
		fmt.Println("网络未正常响应httpCode:")
		fmt.Println(res.StatusCode)
	}

	doc, err := goquery.NewDocumentFromReader(res.Body)

	if err != nil {
		fmt.Println(err)
	}

	//现价
	doc.Find(".word-box .word").Each(func(i int, s *goquery.Selection) {
		text := s.Text()
		fmt.Println(text)
	})
}

func (k Koolearn) levelFour(url string) {
	res, err := http.Get(url)
	if err != nil {
		fmt.Println(err)
	}
	defer res.Body.Close()

	if res.StatusCode != 200 {
		fmt.Println("网络未正常响应httpCode:")
		fmt.Println(res.StatusCode)
	}

	doc, err := goquery.NewDocumentFromReader(res.Body)

	if err != nil {
		fmt.Println(err)
	}

	//现价
	doc.Find(".word_main_list .word_main_list_w span").Each(func(i int, s *goquery.Selection) {
		text := s.Text()
		fmt.Println(strings.TrimSpace(text))
	})
}
